package com.leyou.search.controller;

import com.leyou.common.pojo.PageResult;
import com.leyou.search.pojo.Goods;
import com.leyou.search.pojo.SearchRequest;
import com.leyou.search.pojo.SearchResult;
import com.leyou.search.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SearchController {

    @Autowired
    GoodsService goodsService;

    @RequestMapping("page")
    public ResponseEntity<SearchResult> page(@RequestBody SearchRequest searchRequest){

        // 得到数据之后，去elasticsearch中查询

        SearchResult result = goodsService.search(searchRequest);

        if(result==null){
            return ResponseEntity.notFound().build();
        }

        return ResponseEntity.ok(result);
    }

}
